package com.dxtx.test;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.DrawableContainer;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.dxtx.widget.tagcloud.Tag;
import com.dxtx.widget.tagcloud.TagCloudView;
import com.dxtx.widget.tagcloud.TagsAdapter;

/**
 * Created by user on 2016/12/7.
 */
public class TagCloudDemoActivity extends Activity {
    TagCloudView cloudView;
    private int[] ss = {R.mipmap.baby1, R.mipmap.jt, R.mipmap.liy, R.mipmap.lyf1, R.mipmap.ym, R.mipmap.mm1, R.mipmap.mm2, R.mipmap.baby1, R.mipmap.jt, R.mipmap.liy, R.mipmap.lyf1, R.mipmap.ym, R.mipmap.mm1, R.mipmap.mm2};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);

        cloudView = (TagCloudView) findViewById(R.id.tagCloudView1);
        cloudView.setAdapter(new TagsAdapter() {
            private int width = (int) getResources().getDimension(R.dimen._60dp);

            @Override
            public int getCount() {
                return ss.length;
            }

            @Override
            public View getView(Context context, final int position, ViewGroup parent) {
                ImageView imageView = new ImageView(context);
                imageView.setLayoutParams(new ViewGroup.LayoutParams(width, width));
                imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                StateListDrawable drawable = new StateListDrawable();
                drawable.addState(new int[]{android.R.attr.state_selected}, getResources().getDrawable(R.drawable.light_blue_ring));
                drawable.addState(new int[]{}, null);
                imageView.setImageResource(ss[position]);
                imageView.setBackgroundDrawable(drawable);
                imageView.setPadding(5,5,5,5);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(TagCloudDemoActivity.this, "" + position, Toast.LENGTH_SHORT).show();
                    }
                });
                return imageView;
            }

            @Override
            public Object getItem(int position) {
                return ss[position];
            }

        });
        cloudView.setOnItemSelectListener(new TagCloudView.OnItemSelectListener() {
            @Override
            public void onSelect(View child, int position, Tag tag) {

            }

            @Override
            public void onSelectLockedComplete(View child, int position, Tag tag) {
                /*child.setScaleX(3.5f);
                child.setScaleY(3.5f);*///变大是突然的,不流畅
            }
        });
    }

    public void next(View v) {
        startActivity(new Intent(this, TestActivity.class));
    }
}
